package com.simple.cloud.controller.system;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.mybatisflex.core.paginate.Page;
import com.simple.cloud.core.base.RestResp;
import com.simple.cloud.domain.req.SysRoleReq;
import com.simple.cloud.domain.resp.SysRoleResp;
import com.simple.cloud.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@ApiSort(value = 2)
@Slf4j
@Api(tags = "系统管理-角色")
@RequestMapping("/test/system/role")
@RestController
public class SysRoleController {
    @Resource
    private SysRoleService sysRoleService;

    @ApiOperationSupport(order = 1)
//    @ApiImplicitParam(value = "搜索条件", name = "SysRoleReq", dataType = "SysRoleReq", dataTypeClass = SysRoleReq.class)
    @ApiOperation("分页查询")
    @GetMapping("/getPage")
    public RestResp<Page<SysRoleResp>> getPage(SysRoleReq req){
        Page<SysRoleResp> page = sysRoleService.getPage(req);
        return RestResp.ok(page);
    }
    @ApiOperationSupport(order = 2)
//    @ApiImplicitParam(value = "ID", name = "roleId", dataType = "Long", dataTypeClass = Long.class)
    @ApiOperation("根据ID查询")
    @GetMapping("/getById")
    public RestResp<SysRoleResp> getById(Long roleId){
        SysRoleResp resp = sysRoleService.getById(roleId);
        return RestResp.ok(resp);
    }
    @ApiOperationSupport(order = 3)
//    @ApiImplicitParam(value = "搜索条件", name = "SysRoleReq", dataType = "SysRoleReq", dataTypeClass = SysRoleReq.class)
    @ApiOperation("查询所有")
    @GetMapping("/getAll")
    public RestResp<List<SysRoleResp>> getAll(SysRoleReq req){
        List<SysRoleResp> roles = sysRoleService.getAll(req);
        return RestResp.ok(roles);
    }
    @ApiOperationSupport(order = 4)
//    @ApiImplicitParam(value = "角色信息（ID不存在）", name = "SysRoleReq", dataType = "SysRoleReq", dataTypeClass = SysRoleReq.class)
    @ApiOperation("保存")
    @PostMapping("/save")
    public RestResp<?> save(@RequestBody SysRoleReq req){
        boolean i = sysRoleService.saveAndEdit(req);
        return i ? RestResp.ok() : RestResp.fail();
    }
    @ApiOperationSupport(order = 5)
//    @ApiImplicitParam(value = "角色信息（ID存在）", name = "SysRoleReq", dataType = "SysRoleReq", dataTypeClass = SysRoleReq.class)
    @ApiOperation("编辑")
    @PutMapping("/edit")
    public RestResp<?> edit(@RequestBody SysRoleReq req){
        boolean i = sysRoleService.saveAndEdit(req);
        return i ? RestResp.ok() : RestResp.fail();
    }
    @ApiOperationSupport(order = 6)
//    @ApiImplicitParam(value = "id集合", name = "ids", dataType = "List<Long>", dataTypeClass = List.class)
    @ApiOperation("删除")
    @PostMapping("/deleteByIds")
    public RestResp<?> deleteByIds(@RequestBody List<Long> ids){
        boolean i = sysRoleService.deleteByIds(ids);
        return i ? RestResp.ok() : RestResp.fail("参数不能为空");
    }
}
